forum

home / developersection / forums / how do we check for an integer user input in java

How do we check for an integer user input in java

Anonymous User 2044 07-Oct-2015
Hi Everyone, i am working on  a java application, in which i took  integer input from the user. If the user enter an integer than it is working fine, but in case he inputs a digit or any decimal number , the application throws an exception. So i want to implement a validation for user input, so that only integer values will be accepted. I need a way to check whether the input values is integer type or not, here is a part of my code :

//Taking input through scanner
Scanner sc = new Scanner (System.in);
System.out.println("Enter the number ");
int input = sc.nextInt();






Updated on 07-Oct-2015

I am a content writter !


Message
Can you answer this question?

Answer

1 Answers

Liked By